<?php
declare (strict_types = 1);
namespace app\api\logic;
use app\admin\model\Order;
use app\common\model\Cart as cartModel;
use app\admin\model\OrderEvaluate as orderEvaModel;
use app\admin\model\Config as configModel;
use app\admin\model\User;
use app\admin\model\Goods;
use app\admin\model\GoodsSpecs;
use app\common\model\Address;
use app\common\service\FreightTeplateService as fts;
use app\common\service\CouponService;
use app\admin\model\OrderLog;
use think\facade\Cache; // 使用 Cache facade
use app\admin\model\mk\SeckillPro;
use app\admin\model\mk\Seckill;
use think\facade\Log;
class OrderLogic
{	
	//我的订单
	function lists($args = []){
		$w = [];
		$w['user_id'] = $args['uid'];

		if(isset($args['ordernum'])){
			   $w['ordernum'] = trim($args['ordernum']);
		}
		if(isset($args['os'])){
			  $w2 = order_status_map($args['os']);
			  if(!empty($w2)){
			  	 $w = array_merge($w,$w2);
			  }else{
			  	 $w[] = ['order_status','<',20];
			  }
		}

		 
		$res=  Order::where($w)->order("oid desc")->select();
		foreach($res as &$v){
			 $v['cart'] = cartModel::where("guan_oid",$v['oid'])->select();
			 $v['os'] = order_status_tag($v)['name'] ?? '';
			 $v['total'] = cartModel::where("guan_oid",$v['oid'])->sum("pro_num");
			 if($v['is_pay'] == 0){
			 	  $v['money'] = $v['shi_money'];
			 }
		}
		return $res;
	}
	//订单详细
	function details($args = []){
		  if(isset($args['ordernum']) && !empty($args['ordernum'])){
		  		$data = Order::where("ordernum",$args['ordernum'])->where("user_id",$args['uid'])->find();
		  		$data['os'] = order_status_tag($data)['name'];
		  		$cm = new cartModel();
    	        $cart = $cm->orderCart($data['oid']);
		  }else{
		  	  return ['code'=>100,'msg'=>'缺失参数'];
		  }
		  return ['order'=>$data??[],'cart'=>$cart??[]];
	}
	// 订单取消
	function orderCancel($args = []){
		 if(!isset($args['ordernum'])){
		 	 return ['code'=>100,'msg'=>'缺失参数'];
		 }
		 $w = [];
	     $w['user_id'] = $args['uid'];
    	 $w['ordernum'] = $args['ordernum'];
    	 $res = Order::where($w)->update(['order_status'=>20,'del_time'=>time()+7*24*3600]);  //7天后数据正式删除
    	 if($res){
    	 	return ['code'=>200,'back_type'=>1,'msg'=>'ok'];
    	 }else{
    	 	return ['code'=>100,'back_type'=>1,'msg'=>'删除失败，请重试！'];
    	 }

	}

	//订单评价
	function evaluate($args = []){
		$res = orderEvaModel::where(['uid'=>$args['uid'],'oid'=>$args['oid']])->order("id desc")->select();
		return $res;
	}
	// 提交订单评价
	function subEvaluate($args = []){
        $yi = orderEvaModel::where(['oid'=>$args['oid'],'uid'=>$args['uid']])->find();
 		if($yi){
 			 return ['code'=>100,'back_type'=>1,'msg'=>'已评价过！感谢您的评价'];
 		}
 		if(!isset($args['oid'])){
 			 return ['code'=>100,'back_type'=>1,'msg'=>'缺失参数'];
 		}
 		if(trim($args['txt']) == ''){
 			  return ['code'=>100,'back_type'=>1,'msg'=>'评价内容不能为空'];
 		}
 		$res = orderEvaModel::insert([
 			'uid'=>$args['uid'],
 			'oid'=>$args['oid'],
 			'content'=>$args['txt']??'',
 			'star'=> $args['star'] ?? 5,
 			'create_time'=>time(),
 			'imgs'=>$args['imgs'] ?? '',
 			'pro_id'=>$args['pid'] ?? 0,
 			'shop_id'=>$agrs['shop_id']
 		]);

 		if($res){
 			  return ['code'=>200,'back_type'=>1,'msg'=>'ok'];
 		}else{
 			  return ['code'=>100,'back_type'=>1,'msg'=>'评价失败，请重试'];
 		}
	}
	// 生成订单
	function orderCreate($args = []){
		    $buynow = $args['buynow'] ?? 0;

		    $uid = $args['uid'];
            $cid = $args['cid'] ?? '';
            $qid = $args['qid'] ?? '';  //使用优惠券的id
            $remark = $args['remark'] ?? '';  //用户留言
            $address_id = $args['address'] ?? ''; // 默认地址id
            $ordernum = $args['ordernum'] ?? '';
            $qid = $args['qid'] ?? 0;
            if($buynow == 1){
            		$pid = $args['pid'] ?? 0;
            		$num = $args['num'] ?? 1;
            		$can = $args['can'] ?? 0;
            		if($pid == 0){
            			 return ['code'=>100,'back_type'=>1,'msg'=>'未选择商品'];
            		}
            }else{
            	    if(empty($cid)){
		            	  return ['code'=>100,'back_type'=>1,'msg'=>'未选择商品'];
		            }else{
		            	 $cid = json_decode($cid,true);
		            }
            }
            if(empty($address_id)){
            	 return ['code'=>100,'back_type'=>1,'msg'=>'请选择收货地址'];
            }else{
            	 $address = Address::where(['id'=>$address_id,'user_id'=>$args['uid']])->find();
            }
 
            $sum_money = 0;  //商品总金额
            $jian_money = 0; //各种优惠减去的金额
            $order_money = 0;
            $hui_pro_money = 0; //可以参与优惠的商品总价格 
            $order_freight = 0;
            $order_hui = 0; //订单优惠金额


            if($buynow == 1){
            	    $pro = Goods::where(['id'=>$pid,'status'=>1])->find()->toArray();
            	    if(!$pro){
            	    	 return ['code'=>100,'back_type'=>1,'msg'=>'该商品已下架'];
            	    }
            	    if($can){
            	    	 $spec = GoodsSpecs::where("id",$can)->field("name,price")->find();
            	    	 $pro['price'] = $spec['price'];
            	    }
            	    $sum_money = $pro['price'] * $num;
            	    if($pro['no_hui'] == 0){
            	    	  $hui_pro_money = $pro['price'] * $num;
            	    }
            }else{
		            $w = array();
		            $w['c.user_id'] = $args['uid'];
		            $w['c.is_see'] = 0;
		     		$w['c.shop_id'] = $args['shop_id'];
		 
		            $carts = cartModel::alias("c")->join("goods p", "c.pro_id=p.id", "LEFT")->field("c.*,p.no_hui")->where($w)->whereIn("c.cid",$cid)->select()->toArray();
		            if(empty($carts)){
		            	  return ['code'=>100,'back_type'=>1,'msg'=>'未选择商品'];
		            }
		            foreach($carts as &$v){
		            	 $sum_money += ($v['pro_num'] * $v['pro_price']);
		            	 if($v['no_hui'] == 0){
		            	 	    $hui_pro_money += ($v['pro_num'] * $v['pro_price']);
		            	 }
		            }
	        }

            if($qid){
	        	 $use_quan = Db::name("user_coupon")->where(array("uid" => $uid, 'is_use' => 0, 'id' => $qid))->find();
	             if(!$use_quan){
	             	return ['code'=>100,'back_type'=>1,'msg'=>'优惠券不存在'];
	             }
            }


            $order_money = $sum_money - $order_hui;

            if($ordernum){
            	$up_order = Order::where(['ordernum'=>$ordernum,'user_id'=>$args['uid'],'is_pay'=>0])->update([
            		'money'=>$order_money,
            		'shi_money'=> $sum_money,
            		'qid'=>$qid,
            		'remarks'=>$remark,
            		'uname'=>$address['uname'],
            		'tel'=>$address['phone'],
            		'address'=>$address['area'].",".$address['address'],
            	]);
            	return ['code'=>200,'back_type'=>1,'msg'=>'ok','data'=>$ordernum];
            	exit;
            }
            $order = [];
            $order['user_id'] = $uid;
            $order['create_time'] = time();
            $order['date'] = date("Y-m-d");
            $order['money'] = $order_money;
            $order['ordernum'] = "1".rand(10000, 99999) . time();
            $order['ordermark'] = rand(10000, 99999) . time();
            $order['shi_money'] = $sum_money;
            $order['qid'] = $qid;
            $order['order_status'] = 0;
            $order['remarks'] = $remark;
            $order['uname'] = $address['uname'];
            $order['tel'] = $address['phone'];
            $order['address'] = $address['area'].",".$address['address'];
            $order['shop_id'] = $args['shop_id'];
            $oid = Order::insertGetId($order);
            if($oid){
            		if($buynow == 1){
            		    $res = cartModel::insert([
	    	 	  	   		'pro_num'=>$num,
	    	 	  	   		'user_id'=>$args['uid'],
	    	 	  	   		'can'=>$spec['name'] ?? '默认',
	    	 	  	   		'pro_title'=>$pro['title'],
	    	 	  	   		'pro_img'=>$pro['feng'],
	    	 	  	   		'pro_price'=>$pro['price'],
	    	 	  	   		'pro_cid'=>$pro['cat_id'],
	    	 	  	   		'pro_id' =>$pro['id'],
	    	 	  	   		'shop_id'=>$args['shop_id'],
	    	 	  	   		'is_see'=>1,
	    	 	  	   		'guan_oid'=>$oid
	    	 	  	    ]);     
            		}else{
            			cartModel::alias("c")->where($w)->whereIn("c.cid",$cid)->update(['is_see'=>1,'guan_oid'=>$oid]);
            		}
            		return ['code'=>200,'back_type'=>1,'msg'=>'ok','data'=>$order['ordernum']];
            }else{
            	    return ['code'=>100,'back_type'=>1,'msg'=>'订单创建失败'];
            }


	}
	// 发起支付
	function pay($args = []){

		    $cs = configModel::getShopSettings($args['shop_id']); //获取店铺相关配置
			$ordernum = $args['ordernum'] ?? '';
			if(empty($ordernum)){
				return ['code'=>100,'back_type'=>1,'msg'=>'支付失败'];
			}
			$order = Order::where(['ordernum'=>$args['ordernum'],'user_id'=>$args['uid']])->find();
			if(!$order){
				return ['code'=>100,'back_type'=>1,'msg'=>'订单到期已取消，支付失败,请重试'];
			}
			if($order['is_pay'] == 1){
				 return ['code'=>100,'back_type'=>1,'msg'=>'订单已支付，请勿重复付款'];
			}

			$ordermark = rand(10000, 99999) . time();
			$sm = Order::where(['ordernum'=>$args['ordernum'],'user_id'=>$args['uid'],'is_pay'=>0])->update(['ordermark'=>$ordermark]);
			if(!$sm){
				 return ['code'=>100,'back_type'=>1,'msg'=>'订单支付异常，请重试'];
			}

			$user_wx_openid = User::where("id",$args['uid'])->value("wx_openid");
			if(empty($user_wx_openid)){
				 return ['code'=>100,'back_type'=>1,'msg'=>'无效用户'];
			}
			header("Content-type:text/html;charset=utf-8");
            $obj = array();
            $obj['openid'] = $user_wx_openid;
            $obj['appid'] = $cs['xcx_appid'];
            $obj['mch_id'] = $cs['wxpay_merchant_id'];
            $obj['body'] = "订单支付";
            $obj['out_trade_no'] = $ordermark;
            $obj['total_fee'] = $order['money'] * 100;
            $obj['spbill_create_ip'] = $_SERVER['REMOTE_ADDR'];
            $obj['notify_url'] = "/index/Index/wxnoticy";
            $obj['trade_type'] = "JSAPI";
            $url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
            $apikey = $cs['wxpay_api_key'];
            require_once '../vendor/Wxhb/Wxpay.php';
           // Vendor("Wxhb.Wxpay");
            $res = new \Wxpay();
            $x = $res->pay($url, $obj, $apikey);
            $arr = xmlToArray($x);
            if ($arr['return_code'] == "SUCCESS") {

                $arr['apikey'] = $apikey;
                $arr['appid'] = $cs['xcx_appid'];

                return ['code'=>200,'back_type'=>1,'msg'=>'ok','data'=>$arr];

            } else {
            	return ['code'=>100,'back_type'=>1,'msg'=> "支付失败，请稍后重试,错误信息：" . $arr['return_msg']];
            }


	}

	// 订单结算获取信息合集
	function  orderpay($args = []){
		  $buynow = $args['buynow'] ?? 0;
		  $qid = $args['qid'] ?? 0; //优惠券id
		  $pid = $args['pid'] ?? 0; //如果有此字段 代表直接购买
		  $num = $args['num'] ?? 1;
		  $sum_money = 0;
		  $pay_money = 0;
		  $pro_money = 0;
		  $hui_pro_money = 0;
		  $hui_money = 0;
		  $freight = 0; //运费
		  
		 
		  $user_address = Address::where(['user_id'=>$args['uid'],'default'=>1])->find();
 
		  if($buynow == 1 && $pid){

		  	    $specs_id = $args['can'] ?? 0;

		  		$pro = Goods::where(['id'=>$pid,'status'=>1,'shop_id'=>$args['shop_id']])->find();
		  		if(!$pro){
		  			return ['code'=>100,'back_type'=>1,'msg'=>'商品不存在或已下架'];
		  		}
		  		if($pro['stock'] <= 0){
		  			 return ['code'=>100,'back_type'=>1,'msg'=>'库存不足'];
		  		}     
		  		if($num > $pro['stock']){
		  			  return ['code'=>100,'back_type'=>1,'msg'=>'购买数量超出库存'];
		  		}
		  		if($specs_id){
		  			 $specs = GoodsSpecs::where(['id'=>$specs_id,'goods_id'=>$pid])->find();
		  			 $pro_price = $specs['price'];
		  		}else{
		  			 $pro_price = $pro['price'];
		  		}
		  		
		  		 $pro_money = $pro_price*$num;
		  		 $sum_money = $pro_money;

		  		 $pro['pro_num'] = $num;
		  		 $freghtS = new fts();
		  		 $re_freight = $freghtS->getProFreight($pro,$user_address??[]);
	             if ($re_freight['status'] == 1) {
                      $freight += $re_freight['freight'];
                 }
                 if($pro['no_hui'] == 0){
                 		$hui_pro_money = $num * $pro_price;
                 }
                 $carts[] = [
                 	'pro_num'=>$num,
                 	'pro_title'=>$pro['title'],
                 	'can'=>$specs['name'] ?? '默认',
                 	'no_hui'=>$pro['no_hui'],
                 	'pro_price'=>$pro_price,
                 	'pro_id'=>$pro['id'],
                 	'pro_img'=>$pro['feng']
                 ];

		  }else{
		  	    $w = array();
		  	    if(isset($args['oid'])){  //如果是从我的订单 中未支付订单进来的
		  	    	$w['c.user_id'] = $args['uid'];
		     		$w['c.shop_id'] = $args['shop_id'];
		     		$w['c.guan_oid'] = $args['oid'];
		  	    }else{
		  	    	$w['c.user_id'] = $args['uid'];
		            $w['c.is_see'] = 0;
		     		$w['c.shop_id'] = $args['shop_id'];
		  	    }
	            
	            $carts = cartModel::alias("c")->join("goods p", "c.pro_id=p.id", "LEFT")->field("c.*,p.no_hui,p.freight_type,p.freight_price,p.freight_tpl")->where($w)->select()->toArray();
	            if(empty($carts)){
	            	  return ['code'=>100,'back_type'=>1,'msg'=>'购物车为空'];
	            }
	            $freghtS = new fts();
	            foreach($carts as &$v){
	            	 $pro_money  += $v['pro_num'] * $v['pro_price'];
	            	 $sum_money  += $v['pro_num'] * $v['pro_price'];
	            	 if($v['no_hui'] == 0){
	            	 	  $hui_pro_money += $v['pro_num'] * $v['pro_price'];
	            	 }
		             $re_freight = $freghtS->getProFreight($v,$user_address??[]);
		             if ($re_freight['status'] == 1) {
                          $freight += $re_freight['freight'];
                     }
	            }

		  }
		  //查询有没有满足条件的优惠券可用
		  $uc_s = new CouponService();
		  $keyong_quan = $uc_s->getUserCoupon($args,$hui_pro_money);
		  if($qid){
		  	    $quan_arr = array_column($keyong_quan,NULL,'id');
		  	    if(isset($quan_arr[$qid])){   //鉴定当前选择的优惠券是不是在可用券里面
		  	    	  $hui_money += $quan_arr[$qid]['mian_money'];	
		  	    }
		  }

		  $pay_money = $pro_money + $freight - $hui_money;
		  
		  $data = [
		  	'pro_money'=>sprintf("%.2f", $pro_money),
		  	'freight'=>$freight,
		  	'hui_money'=>$hui_money,
		  	'pay_money'=>sprintf("%.2f", $pay_money),
		  	'carts'=>$carts ?? [],
		  	'user_address'=>$user_address?? -1,
		  	'user_coupon' =>$keyong_quan
		  ];
		  return ['code'=>200,'back_type'=>1,'msg'=>'ok','data'=>$data];




	}

	// 确认收货
	function delivery($args = []){
			$ordernum = $args['ordernum'] ?? '';
			if($ordernum){
				 $order = Order::where(['shop_id'=>$args['shop_id'],'ordernum'=>$ordernum,'is_pay'=>1,'user_id'=>$args['uid']])->find();
				 $s = Order::where(['shop_id'=>$args['shop_id'],'ordernum'=>$ordernum,'is_pay'=>1,'user_id'=>$args['uid']])->update(['order_status'=>9,'receive_time'=>date("Y-m-d H:i:s"),'complete_time'=>date("Y-m-d H:i:s")]);
				 if($s){
				 	  OrderLog::insert(['oid'=>$order['oid'],'log'=>'用户确认收货','time'=>date('Y-m-d H:i:s'),'shop_id'=>$args['shop_id']]);
				 	  return ['code'=>200,'back_type'=>1,'msg'=>'ok']; 
				 }else{
				 	  return ['code'=>100,'back_type'=>1,'msg'=>'操作失败']; 
				 }
			}else{
				return ['code'=>100,'back_type'=>1,'msg'=>'操作失败']; 
			}
	}
	//申请退款
	function refund($args = []){
			$ordernum = $args['ordernum'] ?? '';
			if($ordernum){
				 $refund_reason = $args['refund_reason'] ?? '';

				 $order = Order::where(['shop_id'=>$args['shop_id'],'ordernum'=>$ordernum,'is_pay'=>1,'user_id'=>$args['uid']])->find();

				 $s = Order::where(['shop_id'=>$args['shop_id'],'ordernum'=>$ordernum,'is_pay'=>1,'user_id'=>$args['uid']])->update(['order_status'=>7,'refund_reason'=>$refund_reason]);
				 if($s){
				 	  OrderLog::insert(['oid'=>$order['oid'],'log'=>'用户申请退款，理由：'.$refund_reason,'time'=>date('Y-m-d H:i:s'),'shop_id'=>$args['shop_id']]);
				 	  return ['code'=>200,'back_type'=>1,'msg'=>'ok']; 
				 }else{
				 	  return ['code'=>100,'back_type'=>1,'msg'=>'操作失败']; 
				 }
			}else{
				return ['code'=>100,'back_type'=>1,'msg'=>'操作失败']; 
			}
	}

	// 秒杀订单生成
	function seckillOrder($args = []){
		$uid = $args['uid'];
		$uid = rand(1,999999);
		$productId = $args['sid'] ?? 0;
        if(!isset($productId) || empty($productId)){
        	Log::record($uid.'缺参数');
        	return ['code'=>100,'back_type'=>1,'msg'=>'缺失参数']; 
        }
        $res = SeckillPro::alias("s")->where("s.id",$productId)->join("goods g","s.pro_id=g.id","LEFT")->field("s.*,g.title,g.feng,g.cat_id")->find();
        if(!$res){
        	 return ['code'=>100,'back_type'=>1,'msg'=>'商品已售罄']; 
        }
        if($res['status'] == 0){
        	 return ['code'=>100,'back_type'=>1,'msg'=>'商品已下架']; 
        }
        $Seckill_actives = Seckill::where('id',$res['seckill_id'])->find();
        if(!$Seckill_actives){
        	 return ['code'=>100,'back_type'=>1,'msg'=>'活动已结束']; 
        }
        if($Seckill_actives['status'] == 0){
        	 return ['code'=>100,'back_type'=>1,'msg'=>'活动已结束!']; 
        }
        if($Seckill_actives['limit_num'] > 0){  //该活动所有商品只限购买其中一个商品
        	 $uni_id = "s_".$Seckill_actives['id'];
        }else{
        	 $uni_id = 'sp_'.$productId;
        }
        $expire_time = 3600*24*30;
        try {
            $redis = Cache::store('redis')->handler();
            if (!$redis) {
                throw new \Exception("Redis连接失败");
            }

            //检查库存
	        $stockKey = "seckill:stock:{$productId}";
 			// $redis->set($stockKey,700);
 		    // return $redis->get($stockKey);
            //$current_stock = $redis->get($stockKey);
             // $redis->set($stockKey,1000);
             //return ['code'=>100,'back_type'=>1,'msg'=>$current_stock];

             // 检查用户是否已经参与过秒杀
	        $userParticipationKey = "seckill:user:{$uid}:{$uni_id}:participation";
	        if ($redis->exists($userParticipationKey)) {
	           return ['code'=>100,'back_type'=>1,'msg'=>'已参与了活动']; 
	        }

	        $stock = $redis->decrBy($stockKey, 1);
	        if ($stock < 0) {
	            $redis->incrBy($stockKey, 1); // 回滚库存
	            return ['code' => 100, 'msg' => '库存不足'];
	        }
	        // 创建订单
	        $order_return = $this->createSeckillOrder($args,$res);
	        if($order_return['code'] == 100){
	        	$redis->incrBy($stockKey, 1); // 回滚库存
	            return ['code' => 100, 'msg' => '创建订单失败'];
	        }
 

 			$orderId = $order_return['oid'];
 			// 设置订单过期时间
	        $orderKey = "order:{$orderId}";
	        $redis->set($orderKey,json_encode(['time'=>time(),'mk_id'=>$productId,'uni_id'=>$uni_id]));

	        // 标记用户已参与
            $redis->set($userParticipationKey,1); // 与订单过期时间相同

            Log::record($uid.'参与了');

 			return ['code'=>200,'back_type'=>1,'msg'=>'ok']; 

            
        } catch (\Exception $e) {
            // 处理异常
            return false;
        }


	}

	function createSeckillOrder($args,$res = []){

			$uid = $args['uid'];
            $address = Address::where(['user_id'=>$uid,'default'=>1])->find();
    		$order = [];
            $order['user_id'] = $uid;
            $order['create_time'] = time();
            $order['date'] = date("Y-m-d");
            $order['money'] = $res['seckill_price'];
            $order['ordernum'] = "1".rand(10000, 99999) . time();
            $order['ordermark'] = rand(10000, 99999) . time();
            $order['shi_money'] = $res['seckill_price'];
            $order['order_status'] = 0;
            $order['types'] = 1;
            $order['uname'] = $address['uname'];
            $order['tel'] = $address['phone'];
            $order['address'] = $address['area'].",".$address['address'];
            $order['shop_id'] = $args['shop_id'];
            $order['mk_id'] = $res['id'];

            $result = Order::transaction(function () use ($order, $uid, $res, $args, &$oid, &$cart_id) {
			    $oid = Order::insertGetId($order);
			    if ($oid) {
			        $cart_id = cartModel::insert([
			            'pro_num' => 1,
			            'user_id' => $uid,
			            'can' => $can ?? '默认',
			            'pro_title' => $res['title'],
			            'pro_img' => $res['feng'],
			            'pro_price' => $res['seckill_price'],
			            'pro_cid' => $res['cat_id'],
			            'pro_id' => $res['pro_id'],
			            'shop_id' => $args['shop_id'],
			            'guan_oid' => $oid,
			            'is_see' => 1
			        ]);
			        return $cart_id;
			    }
			    return false;
			});

			if ($result) {
			    return ['code' => 200, 'msg' => 'ok', 'oid' => $oid];
			} else {
			    return ['code' => 100, 'back_type' => 1, 'msg' => 'Cart Error!'];
			}


	            // $oid = Order::insertGetId($order);
	            // if($oid){

	    		//     $cart_id = cartModel::insert([
		 	  	//    		'pro_num'=>1,
		 	  	//    		'user_id'=>$uid,
		 	  	//    		'can'=>$can ?? '默认',
		 	  	//    		'pro_title'=>$res['title'],
		 	  	//    		'pro_img'=>$res['feng'],
		 	  	//    		'pro_price'=>$res['seckill_price'],
		 	  	//    		'pro_cid'=>$res['cat_id'],
		 	  	//    		'pro_id' =>$res['pro_id'],
		 	  	//    		'shop_id'=>$args['shop_id'],
		 	  	//    		'guan_oid'=>$oid,
		 	  	//    		'is_see'=>1
		 	  	//    ]);
	    		//    if($cart_id){
	    		//    		  return ['code'=>200,'msg'=>'ok','oid'=>$oid];
	    		//    }else{
	    		//    	      return ['code'=>100,'back_type'=>1,'msg'=>'Cart Error!']; 		
	    		//    }

	            // }else{
	            //      return ['code'=>100,'back_type'=>1,'msg'=>'订单创建失败']; 		
	            // }
	}
}